﻿using B.Rabbit.DataBase.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.Rabbit.DataBase.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ImageController : ControllerBase
    {
        /// <summary>
        /// 图片上传
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<string>Img(IFormFile file)
        {
            ApiResult<string> res = new ApiResult<string>();
            var path = Directory.GetCurrentDirectory() + @"/wwwroot/Img/" + file.FileName;
            using(var fs=new FileStream(path,FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Close();
            }
            res.data = "http://localhost:5264/Img/" + file.FileName;
            res.msg = "上传成功";
            res.code = ErrorCode.StatusCode.Ok;
            return res;
        }
    }
}
